package io.renren.modules.app.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.renren.common.utils.R;
import io.renren.modules.PCguanli.entity.LineEntity;
import io.renren.modules.PCguanli.entity.ViolationRecordsEntity;
import io.renren.modules.app.dao.ViolationDao;
import io.renren.modules.app.entity.ViolationEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/app/user")
public class ViolationController {

    @Autowired
    private ViolationDao violationDao;

    @GetMapping("/violation")
    public R getRecordByUserId(@RequestParam int userId) {
        List<ViolationEntity> records = violationDao.selectList(new LambdaQueryWrapper<ViolationEntity>()
                .eq(ViolationEntity::getUserId, userId)
                .orderByAsc(ViolationEntity::getTime)
        );
        if (records.isEmpty()) {
            return R.error("该用户没有违规").put("data",null);
        } else {
            return R.ok("success").put("data",records);
        }
    }
}
